package com.five.monkey.feign.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.five.monkey.enums.StatusEnum;
import com.five.monkey.feign.provider.convert.GraphConvert;
import com.five.monkey.feign.provider.dao.mapper.GraphMapper;
import com.five.monkey.feign.provider.dao.model.GraphModel;
import com.five.monkey.feign.provider.service.GraphService;
import com.five.monkey.vo.GraphVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author 狻猊
 * @date 2021/8/9 下午9:30
 */
@Service
public class GraphServiceImpl implements GraphService {

    @Autowired
    private GraphMapper graphMapper;


    @Override
    public GraphVo findById(Long id) {
        GraphVo vo = null;
        GraphModel graphModel = graphMapper.selectById(id);
        if (Objects.nonNull(graphModel) && StatusEnum.isValid(graphModel.getStatus())) {
            vo = GraphConvert.model2vo(graphModel);
        }
        return vo;
    }

    @Override
    public List<GraphVo> findByUserId(Long userId) {
        LambdaQueryWrapper<GraphModel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(GraphModel::getUserId, userId);
        lambdaQueryWrapper.eq(GraphModel::getStatus, StatusEnum.valid.getStatus());
        List<GraphModel> graphList = graphMapper.selectList(lambdaQueryWrapper);
        return graphList.stream().map(GraphConvert::model2vo).collect(Collectors.toList());
    }
}
